<template>
  <div class="login">
    <div class="loginForm">
      <!-- 头像 -->
      <div class="title">
        <img src="../assets/logo.png" alt="" />
      </div>
      <el-form ref="form" :model="loginForm" label-width="0px">
        <!-- 用户名 -->
        <el-form-item label="">
          <el-input v-model="loginForm.username" prefix-icon="iconfont icon-yonghuming"></el-input>
        </el-form-item>
        <!-- 密码 -->
        <el-form-item label="">
          <el-input type="password" v-model="loginForm.password" prefix-icon="iconfont icon-mima"></el-input>
        </el-form-item>
        <div class="login_btn">
          <el-button type="primary" @click="subForm()">登录</el-button>
          <el-button type="info">重置</el-button>
        </div>
      </el-form>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      //登录
      loginForm: {
        username: "admin",
        password: "123456",
      },
    };
  },
  methods:{
    async subForm(){
      //请求
      const {data:res}=await this.$http.post('/login',this.loginForm)
    
      if(res.meta.status!==200) return this.$message.error('登录失败');
      //成功，保存token
      window.sessionStorage.setItem('token',res.data.token);
      this.$router.push('/home')

    }
  }
};
</script>
<style lang="less" scoped>
.login {
  height: 100%;
  background-color: #2b4b6b;
  .loginForm {
    width: 450px;
    height: 320px;
    background-color: white;
    border-radius: 5px;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    .title {
      width: 150px;
      height: 150px;
      border: 1px solid #ccc;
      border-radius: 50%;
      position: absolute;
      left: 50%;
      transform: translate(-50%, -50%);
      padding: 5px;
      border: 1px solid #ccc;
      padding: 5px;
      background-color: white;
      box-shadow: 0 0 5px 5px #fff;
      img {
        widows: 100%;
        height: 100%;
        border-radius: 50%;
        background-color: #ccc;
      }
    }
  }
}
.el-form{
  width: 100%;
  position: absolute;
  bottom:0;
  padding: 20px;
  box-sizing: border-box;
  .login_btn{
    display: flex;
    justify-content: flex-end;
  }
}
</style>